package sctu.edu.java.year2016.team03.huzhou.day20160606.chapter9_1;
import java.util.Scanner;
/**
 *Created by Administrator on 2016/6/6.
 *编写Java程序，创建一个类，并在类中创建一个成员内部类，通过成员内部类
 *计算1到任意数的和的操作，并在外部类中进行测试。
 */
public class SumRank {
    private int Rank;

        private class Sum{
            int Sum = 0;
            int theWay(int Rank) {
                if (Rank == 1) {
                    return Sum += 1;
                }
                else {
                    Sum += Rank;
                    return theWay(Rank - 1);
                }
            }
        }

        void getSumOf() {
            Sum rank = new Sum();
            System.out.println("Answer is:"+rank.theWay(Rank));
        }

        public void setRank(int rank) {
            Rank = rank;
        }


            public static void main(String[] args) {
            System.out.print("Set the Rank:");

            SumRank rank = new SumRank();
            Scanner scan = new Scanner(System.in);
            rank.setRank(scan.nextInt());
            rank.getSumOf();
        }

    }


